package com.fastloan.jn.mgt.process.controller;

import com.fastloan.jn.mgt.process.model.JnApplicationApprovalReview;
import com.fastloan.jn.mgt.process.model.vo.ApplicationApprovalReviewVo;
import com.fastloan.jn.mgt.process.service.AppApproveUserService;
import com.fastloan.jn.mgt.process.service.ApplicationApprovalReviewService;
import com.fastloan.safe.core.util.ManagerKit;
import com.kawins.base.baseabs.BaseController;
import com.kawins.result.ResultEnum;
import com.kawins.result.ResultTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 审贷会排审
 *
 * @author chenkai
 *         createTime 2017-02-2017/2/8 11:03
 */
@RestController
@RequestMapping("/api/web/applicationApprovalReview")
public class ApplicationApprovalReviewController extends BaseController<JnApplicationApprovalReview> {
    /**
     * 审贷会排审
     */
    @Autowired
    private ApplicationApprovalReviewService tApplicationApprovalReviewService;

    @Autowired
    private AppApproveUserService appApproveUserService;

    /**
     * 分页查询审贷会排审
     *
     * @return 分页信息
     */
    @RequestMapping("/pageList")
    public ResultTo queryAll() {
        Map<String, Object> map = new HashMap<>(1);
        map.put("orgId", ManagerKit.getUserId());
        //map.put("customerType", ShiroKit.getOrgType());
        return dataPage("queryReview", map);
    }

    /**
     * 按id查询审贷会排审信息
     *
     * @param id 审贷会id
     * @return 审贷会排审信息
     */
    @GetMapping("/{id}")
    public ResultTo getByAppId(@PathVariable("id") int id) {
        Map<Object, Object> map = new HashMap<>();
        map.put("id", id);
        List<ApplicationApprovalReviewVo> approvalReviewVos = tApplicationApprovalReviewService.queryReview(map);
        return new ResultTo().setData(approvalReviewVos);
    }

    /**
     * 更新排审信息
     *
     * @param review 审贷会排审
     * @return 数据库变记录
     */
    @PutMapping
    public ResultTo update(@ModelAttribute JnApplicationApprovalReview review) {
        Integer mark = tApplicationApprovalReviewService.updateByPrimaryKeySelective(review);
        return mark != 0 ? new ResultTo().setData(mark) : new ResultTo(ResultEnum.OPERATION_FAILED);
    }

    /**
     * 新增排审信息(添加审贷会成员信息)
     *
     * @param userIds 用户id
     * @param userIds 审贷会信息
     * @return 数据库变记录
     */
    @PostMapping("/initialization")
    public ResultTo initialization(@RequestParam("userIds") String userIds, JnApplicationApprovalReview applicationApprovalReview) {
        int initialization = appApproveUserService.initialization(userIds, applicationApprovalReview);
        return initialization != 0 ? new ResultTo().setData(initialization) : new ResultTo(ResultEnum.OPERATION_FAILED, "此进件无需重复排审");
    }
}
